<template>
  <div>
    <el-form :inline="true" label-width="80px">

      <el-form-item label="类型">
        <el-select v-model="queryParams.jointype" placeholder="类型" clearable size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="类型" clearable size="small">
          <el-option
            v-for="dict in assetStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>

    </el-form>
    <el-table v-loading="loading" :data="postList">
      <el-table-column label="类型" align="center" prop="jointype" :formatter="typeFormat"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="typeFormat"/>
      <el-table-column label="原有额度" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.oldbalance|currencyFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column label="变更额度" align="center" prop="fee">
        <template slot-scope="scope">
          <span>{{scope.row.changebalance|currencyFilter}}</span>
        </template>
      </el-table-column>

      <el-table-column label="新额度" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.newbalance|currencyFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" :show-tooltip-when-overflow="true"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="createtime"
                       :show-tooltip-when-overflow="true"></el-table-column>
    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {assetLogList} from "@/api/channel/asset";

  export default {
    props: {
      row: {
        type: Object,
        require: true
      }
    },
    data() {
      return {
        daterange: '',
        loading: true,
        total: 0,
        postList: [],
        typeOptions: [],
        assetStatusOptions: [],
        // 查询参数
        queryParams: {
          channelId: undefined,
          pageNum: 1,
          pageSize: 10,
        },
      };
    },
    created() {
      console.log(this.row);
      this.queryParams.channelId = this.row.id;

      this.getDicts("yy_asset_status").then(response => {
        this.assetStatusOptions = response.data;
      });
      this.getDicts("yy_channel_type").then(response => {
        this.typeOptions = response.data;
      });

      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        assetLogList(this.queryDateRange(this.queryParams, this.daterange)).then(response => {
          console.log(response.rows);
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 岗位状态字典翻译
      typeFormat(row, column) {
        console.log(row);
        let options;
        if (column.property === 'jointype') {
          options = this.typeOptions;
        } else if (column.property === 'status') {
          options = this.assetStatusOptions;
        }
        return this.selectDictLabel(options, row[column.property]);
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      }
    }
  };
</script>
